package com.csg.web.interceptor;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import java.io.IOException;

/**
 * 自定义过滤器
 *
 * @author george
 */
@Slf4j
public class CustomFilter implements Filter {

    /**
     * 初始化方法
     *
     * @param filterConfig
     * @throws ServletException
     */
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("Custom Filter Init");
    }

    /**
     * filter过滤器处理
     *
     * @param request  请求数据
     * @param response 响应数据
     * @param chain    过滤器链
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info("Custom Filter Start");
        long start = System.currentTimeMillis();
        chain.doFilter(request, response);
        long finish = System.currentTimeMillis();
        log.info("Custom Filter 耗时：" + (finish - start));
        log.info("Custom Filter Finish");
    }

    /**
     * 销毁方法
     */
    @Override
    public void destroy() {
        log.info("Custom Filter Destroy");
    }
}
